package ScriptsGenericos
{
	import mx.core.Application;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;

	public class PopUpManagerPRS extends PopUpManager
	{
		public static var arrayPantallas:Array = new Array();
		
		public function PopUpManagerPRS()
		{
			super();
		}
		
		public static function crearPopUp(componente:UIComponent, applicationInstance: Object = null, conservarAlto:Boolean=false):void{
			if (applicationInstance == null)
	      	{
	        	applicationInstance = Application.application;
	     	}
			
			//PopUpManagerPRS.removerTodos(applicationInstance);
			
			PopUpManager.addPopUp(componente,applicationInstance as UIComponent,true);
			PopUpManager.centerPopUp(componente);
			
			//PopUpManagerPRS.arrayPantallas.push(componente);

			if(!conservarAlto)
				componente.height = obtenerAltoPantalla(componente);
		}
		
		public static function removerPopUp(componente:UIComponent):void{
			try{
				//PopUpManagerPRS.arrayPantallas.pop();
				PopUpManager.removePopUp(componente);
				
				/*if(PopUpManagerPRS.arrayPantallas.length > 0){
					PopUpManagerPRS.crearPopUp(PopUpManagerPRS.arrayPantallas.pop() as UIComponent);
				}*/
			}
			catch(e:Error){}
		}
		
		public static function removerTodos(applicationInstance: Object = null):void{
			PopUpUtils.closeAllPopups(applicationInstance);
		}
		
		protected static function obtenerAltoPantalla(componente:UIComponent):Number{
			if(componente.height > componente.parentApplication.height)
				return componente.parentApplication.height;
			
			return componente.height;	
		}
	}
}